package mn.idax.exchange.otc.service.impl;

import com.alibaba.fastjson.JSON;
import mn.idax.exchange.otc.service.MqService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.JmsException;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Service;

/**
 * @Auther: dison
 * @Date: 2018/8/3 09:59
 * @Description:
 */
@Service
public class MqServiceImpl implements MqService {

    @Autowired
    private JmsTemplate jmsTemplate;

    @Override
    public void send(String destinationName, String textMessage) throws JmsException {
        this.jmsTemplate.convertAndSend(destinationName,textMessage);
    }

    @Override
    public void sendJSONByEntity(String destinationName, Object entity) throws JmsException {
        this.jmsTemplate.send(destinationName,session -> session.createTextMessage(JSON.toJSONString(entity)));
    }
}
